<?php

  //
  // Memorii Web
  // script/db.php
  //
  // Access to the database
  //
  
  function db_connect() {
  	$db_url 			= 'localhost:8888';
  	$db_login 		= 'root';
  	$db_password 	= 'root';
  	$db_name 			= 'memorii';
  	
 		$db_connection = mysql_connect($db_url, $db_login, $db_password)
				or die('Unable to connect to the database.');
		mysql_select_db($db_name, $db_connection) or die ('Unable to connect to the database.');
		
		return $db_connection;
	}
	
	function db_disconnect($db_connection) {
		mysql_close($db_connection);
	}
	
	function db_generate_id() {
		return md5(uniqid(mt_rand(), true));
	}
	
	function db_clear_input(&$input) {
		// TODO: preg_replace
		$input = urldecode($input);
		$input = str_replace('\'', '', $input);
	}
	
	function db_query($db_connection, $query) {
		return mysql_query($query, $db_connection);
	}
	
	function db_query_array($db_connection, $query) {
		$result = mysql_query($query, $db_connection);
		return mysql_fetch_array($result);
	}
	
	function db_query_arrays($db_connection, $query) {
		$result = mysql_query($query, $db_connection);
		$tabs = array();
		while ($tab = mysql_fetch_array($result) ) {
			$tabs[] = $tab;
		}
		return $tabs;
	}
	
	include('db_user.php');
	include('db_word.php');
	include('db_folder.php');
?>